package com.yaozheng.vocationaltraining.view;

import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.activity.HomeActivity;
import com.yaozheng.vocationaltraining.adapter.PKSaiKuangListAdapter;
import com.yaozheng.vocationaltraining.bean.GameResultBean;
import com.yaozheng.vocationaltraining.bean.PKSaiKuangBean;
import com.yaozheng.vocationaltraining.utils.BitmapLoader;

import java.util.ArrayList;

/**
 * Created by moon on 2017/11/19.
 */

public class PKSaiResultDialog {
    private BitmapLoader userBitmapLoader;

    private HomeActivity context;
    private Dialog dialog;
    private LinearLayout lLayout_bg;
    private ImageView closed_imageview;

    private TextView title_textview;
    private TextView cate_name_textview;
    private TextView rule_name_textview;
    private TextView result_textview;
    private Button confirm_button;
    private Button look_button;


    private Display display;

    private GameResultBean resultBean;


    public PKSaiResultDialog(HomeActivity context, GameResultBean resultBean ) {
        this.context = context;
        userBitmapLoader = new BitmapLoader(Glide.with(context), R.drawable.user_img);
        this.resultBean = resultBean;
        WindowManager windowManager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        display = windowManager.getDefaultDisplay();
    }

    public PKSaiResultDialog builder() {
        //
        View view = LayoutInflater.from(context).inflate(
                R.layout.view_pksai_result_dailog, null);

        initViewUI(view);


        title_textview.setText(resultBean.isResult()?"恭喜您":"提示");
        cate_name_textview.setText(resultBean.getCateName());
        rule_name_textview.setText(resultBean.getRuleName());
        result_textview.setText(resultBean.isResult()?"您获得了胜得":"您输了");

        dialog = new Dialog(context, R.style.AlertDialogStyle);
        dialog.setContentView(view);

        //
        lLayout_bg.setLayoutParams(new FrameLayout.LayoutParams((int) (display
                .getWidth() * 0.7), LinearLayout.LayoutParams.WRAP_CONTENT));

        closed_imageview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        confirm_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
                context.openPKResultFragment(resultBean.getId());
            }
        });
        return this;
    }

    private void initViewData() {


    }

    private void initViewUI(View view) {
        lLayout_bg = (LinearLayout) view.findViewById(R.id.lLayout_bg);
        closed_imageview = (ImageView) view.findViewById(R.id.closed_imageview);

        title_textview = (TextView) view.findViewById(R.id.title_textview);
        cate_name_textview = (TextView) view.findViewById(R.id.cate_name_textview);
        rule_name_textview = (TextView) view.findViewById(R.id.rule_name_textview);
        result_textview = (TextView) view.findViewById(R.id.result_textview);

        confirm_button = (Button) view.findViewById(R.id.confirm_button);
        look_button = (Button) view.findViewById(R.id.look_button);


    }

    public void show() {
       // setLayout();
        dialog.show();
    }
}
